package pattern.behavior.observer.spring;

import cn.hutool.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author : Rookie
 * @description :
 * @date : 2023/8/26
 */
@Component
public class CustomEventRunner implements ApplicationRunner {

    @Autowired
    private EventPublisherService eventPublisherService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", UUID.randomUUID().toString());
        jsonObject.put("currTime",System.currentTimeMillis());
        eventPublisherService.publishCustomEvent(jsonObject);
    }
}
